home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / KMShaders / KMVenus.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  3.1 KB  |  102 lines

  1. /* modified by wave to KMVenus for name space protection... */
  2. /*
  3.  * venus.sl - surface for a very cloudy planet like Venus.
  4.  *
  5.  *
  6.  * DESCRIPTION:
  7.  *      When put on a sphere, sets the color to look like a densely
  8.  *   clouded planet, very much like the real Venus appears in UV.
  9.  *      The shader works by creating a fractal turbulence function over
  10.  *   the surface to simulate the clouds.  Strong Coriolis forces are
  11.  *   simulated to give the twisting of clouds that is typically seen
  12.  *   on Venus.
  13.  *
  14.  *
  15.  * PARAMETERS:
  16.  *    Ka, Kd - the usual meaning
  17.  *    offset, scale - control the linear scaling of the cloud value.
  18.  *    twist - controls the twisting of the clouds due to Coriolis forces.
  19.  *    omega - controls the fractal characteristics of the clouds
  20.  *    octaves - the number of octaves of noise to sum for the clouds.
  21.  *
  22.  *
  23.  * HINTS:
  24.  *    The default values for the shader assume that the planet is
  25.  *    represented by a unit sphere.  The texture space and/or parameters
  26.  *    to this shader will need to be altered if the size of your planet
  27.  *    is radically different.
  28.  *
  29.  *
  30.  * AUTHOR: Ken Musgrave.
  31.  *    Conversion to Shading Language and minor modifications by Larry Gritz.
  32.  *
  33.  *
  34.  * REFERENCES:
  35.  *    _Texturing and Modeling: A Procedural Approach_, by David S. Ebert, ed.,
  36.  *    F. Kenton Musgrave, Darwyn Peachey, Ken Perlin, and Steven Worley.
  37.  *    Academic Press, 1994.  ISBN 0-12-228760-6.
  38.  *
  39.  *
  40.  * HISTORY:
  41.  *    ???? - Venus texture developed by F. Ken Musgrave.
  42.  *    Feb 1994 - Conversion to Shading Language by L. Gritz
  43.  *
  44.  * last modified 1 March 1994 by lg
  45.  */
  46.  
  47.  
  48.  
  49. #define TWOPI (2*PI)
  50.  
  51.  
  52. /* Use signed noise on [-1,1] */
  53. #define snoise(x) ((2*noise(x))-1)
  54.  
  55.  
  56.  
  57. surface
  58. KMVenus (float Ka = 1, Kd = 1;
  59.          float offset = 1;
  60.          float scale = 0.6;
  61.          float twist = 0.22;
  62.          float omega = 0.65;
  63.          float octaves = 8;)
  64. {
  65.   point Ptexture;           /* the shade point in texture space */
  66.   point PtN;                /* normalized version of Ptexture */
  67.   point PP;                 /* Point after rotation by coriolis twist */
  68.   float rsq;                /* Used in calculation of twist */
  69.   float angle;              /* Twist angle */
  70.   float sine, cosine;       /* sin and cos of angle */
  71.   float l, o, a, i;         /* Loop control for fractal sum */
  72.   float value;              /* Fractal sum is stored here */
  73.  
  74.   /* Transform to texture coordinates */
  75.   Ptexture = transform ("shader", P);
  76.  
  77.   /* Calculate Coriolis twist, yielding point PP */
  78.   PtN = normalize (Ptexture);
  79.   rsq = xcomp(PtN)*xcomp(PtN) + ycomp(PtN)*ycomp(PtN);
  80.   angle = twist * TWOPI * rsq;
  81.   sine = sin (angle);
  82.   cosine = cos (angle);
  83.   PP = point (xcomp(Ptexture)*cosine - ycomp(Ptexture)*sine,
  84.           xcomp(Ptexture)*sine + ycomp(Ptexture)*cosine,
  85.           zcomp(Ptexture));
  86.  
  87.   /* Compute VLfBm */
  88.   l = 1;  o = 1;  a = 0;
  89.   for (i = 0;  i < octaves;  i += 1) {
  90.       a += o * snoise (PP * l);
  91.       l *= 2;
  92.       o *= omega;
  93.     }
  94.  
  95.   value = abs (offset + scale * a);
  96.  
  97.   /* Shade like matte, but with color scaled by cloud color */
  98.   Oi = 1;
  99.   Ci = Os * (value * Cs) * (Ka * ambient() +
  100.                 Kd * diffuse(faceforward(normalize(N),I)));
  101. }
  102.